package client;

import java.awt.Toolkit;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

import javax.swing.JFrame;

import client.communication.ClientCommunicator;
import client.communication.listeners.PingListener;

import communication.Communicator;
import components.AuthenticationContentPanel;
import components.AuthenticationJFrame;

public class Client
{
	private ClientCommunicator communicator;
	private AuthenticationContentPanel contentPane;
	
	public void run()
	{
		AuthenticationJFrame window = new AuthenticationJFrame();
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		
		try
		{
			communicator = new ClientCommunicator(new Socket("127.0.0.1", 62455), this);
		
			communicator.start();
		}
		catch (InstantiationException e)
		{
			e.printStackTrace();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		
		this.contentPane = new AuthenticationContentPanel(this);
		
		window.setContentPane(contentPane);
		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		window.setResizable(false);
		window.setSize(500, 225);
		window.setVisible(true);
		window.setLocation(toolkit.getScreenSize().width / 2 - window.getWidth() / 2, toolkit.getScreenSize().height / 2 - window.getHeight() / 2);
	}
	public ClientCommunicator getCommunicator()
	{
		return communicator;
	}
	public static void main(String[] args)
	{
		Client client = new Client();
		
		client.run();
	}
	public void setStatusText(String text)
	{
		contentPane.setStatusText(text);
	}
}
